Ext.onReady(function(){

	Ext.BLANK_IMAGE_URL = '/extjs-crud-grid/ext-3.2.1/resources/images/default/s.gif';


	Ext.QuickTips.init();

	// invalid markers to sides
	Ext.form.Field.prototype.msgTarget = 'side';

	 var loginForm = new Ext.FormPanel({
		 xtype:'form'
		 ,id:'login-form'
		 ,defaultType:'textfield'
		 ,frame:true
		 ,method:'post'
		 ,url:'login/login.action'
		 ,defaults:{anchor:'95%'}
		 ,items:[{
		 fieldLabel:'User name'
		 ,id:'username'
		 },{
		 fieldLabel:'Password'
		 ,id:'password'
		 ,inputType:'password'

		 }]
		 ,buttonAlign:'right'
		 ,buttons:[
		           {text:'Not registered?',
		        	   handler:function() {
		        		   window.location = 'register.jsp';
		        		}},
		           {text:'Submit' ,
		        	   handler:function() {
		        		   Ext.getCmp('login-form').getForm().submit(
		        				   {params:{cmd:'submit'},
		        					waitMsg: 'Login...',
		        					success: function() 
		        					{ 
		        						
		        					  // 	Ext.Msg.alert('Complete', 'Congratulations!! Login Complete, Please login!'); 
		        					   	window.location = 'main.jsp';
						            },
                         			failure: function(form, action) {
                         				Ext.Msg.alert('Complete', 'Username : '+ action.result.user +' does not match with the given password'); 
                         				loginForm.getForm().reset();
                         			}

		        				   });
		        	   }
		        		
		           
		           
		           }	        	   
		           ]
	 });
	
	
	 var win = new Ext.Window({
			 id:'LoginForm'
			 ,width:300
			 ,height:130
			 ,layout:'fit'
			 ,border:false
			 ,closable:false
			 ,renderTo:Ext.getBody()
			 ,frame:true
			 ,title:'Login'
			 ,items:[loginForm]
		 });
		  
		 // show window
		 win.show();
		 
		 


});
